# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=coreutils
pkgver=8.24
pkgrel=1
pkgdesc="The basic file, shell and text manipulation utilities of the GNU operating system"
arch=('i686' 'x86_64')
license=('GPL3')
url="http://www.gnu.org/software/coreutils"
groups=('base')
depends=('gmp' 'libiconv' 'libintl')
makedepends=('gmp-devel' 'libiconv-devel' 'gettext-devel' 'help2man')
install=${pkgname}.install
source=(ftp://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.xz{,.sig}
        001-coreutils-8.24-3.src.patch
        005-manifest.patch
        006-msys1-0x0d.patch
        008-msys2-src.patch
        009-msysize.patch)
md5sums=('40efdbce865d2458d8da0a9dcee7c16c'
         'SKIP'
         '69f29d9683cf95bdfd6b1111e6e79ee4'
         '78fdb4dd2df493df4ae24448e964d076'
         '61aa69467df9084fe4611b737723f97b'
         '755cd79ba7211b9ab73b0b2f0ec9c276'
         'a159a8ab3cd0a5129f420db8e1102770')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}

  patch -p2 -i $srcdir/001-coreutils-8.24-3.src.patch
  patch -p1 -i $srcdir/005-manifest.patch
  patch -p1 -i $srcdir/006-msys1-0x0d.patch
  patch -p1 -i $srcdir/008-msys2-src.patch
  patch -p1 -i $srcdir/009-msysize.patch

  autoreconf -fi
  sed -i -e 's|\(libstdbuf\.so\)$(EXEEXT)|\1|g' Makefile.in
}

build() {
  [[ -d $srcdir/build-${CHOST} ]] && rm -rf $srcdir/build-${CHOST}
  mkdir -p $srcdir/build-${CHOST} && cd $srcdir/build-${CHOST}

  ../${pkgname}-${pkgver}/configure \
    --build=${CHOST} \
    --prefix=/usr \
    --libexecdir=/usr/lib \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --program-transform-name=s/kill/gkill/ \
    --without-libintl-prefix \
    --without-libiconv-prefix \
    --enable-install-program=arch,hostname \
    --enable-no-install-program=uptime

  make
}

package() {
  cd ${srcdir}/build-${CHOST}
  make DESTDIR=${pkgdir} install

  #mkdir -p ${pkgdir}/usr/etc
  install -Dm644 ${srcdir}/${pkgname}-${pkgver}/src/dircolors.hin ${pkgdir}/etc/DIR_COLORS
}
